import java.util.Scanner;

/**
 * @Author: XXHH
 * @CreateTime: 2024-12-23
 */
public class Demo32 {
    public static void main(String[] args) {
        Object locker = new Object();
        Thread t1 = new Thread(()->{
            try {
                System.out.println("t1 wait之前...");
                synchronized (locker) {
                    locker.wait();
                }
                System.out.println("t1 wait之后...");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        Thread t2 = new Thread(()->{
            try {
                System.out.println("t2 wait之前...");
                synchronized (locker) {
                    locker.wait();
                }
                System.out.println("t2 wait之后...");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        Thread t3 = new Thread(()->{
            Scanner scanner = new Scanner(System.in);
            System.out.println("随意输入,同时唤醒t1和t2线程");
            scanner.next();
            synchronized (locker){
                locker.notifyAll();
            }

        });
        t1.start();
        t2.start();
        t3.start();
    }
}
